#!/bin/bash -ex

CMAKE_SCRIPT_DIR="$(realpath $(dirname ${0}))"
SCRIPT_DIR="$(dirname ${CMAKE_SCRIPT_DIR})"
ROOT_REPO_DIR="$(dirname ${SCRIPT_DIR})"
PANDA_PACKAGE_DIR="${ROOT_REPO_DIR}/panda_package"

BUILD_DIR="${ROOT_REPO_DIR}/build"
mkdir -p "${BUILD_DIR}"

cd "${PANDA_PACKAGE_DIR}"
npm i

NPM_PANDA_DIR="${PANDA_PACKAGE_DIR}/node_modules/@panda/sdk/linux_host_tools"

cd "${BUILD_DIR}"

rm -rf *
cmake \
"${ROOT_REPO_DIR}/CMakeLists.txt" \
-GNinja -B "${BUILD_DIR}" \
-DNPM_KOALA_PANDA_PATH="${NPM_PANDA_DIR}" \
-DUSE_LOCAL_BUILD_PANDA=OFF
